﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;
using System.IO;

public partial class _Default : Basic
{
    public string strPool = "";  //乾坤股票池
    public string strGgph = "";  //个股排行
    public string strHotBk = "";  //
    public string strZcQm = "";  //强买榜、增仓榜
    public string strQsRs = "";  //强势弱势板块
    public string strCWB = "";  //仓位表
    public string strScjd = "";  //
    public string strScjd2 = "";  //
    public string strRdbk = "";  //热点板块

    protected void Page_Load(object sender, EventArgs e)
    {
        strScjd = sbScjd().ToString() ;

        strScjd2 = sbScjd3().ToString();

        strZcQm = sb强买增仓榜().ToString();

        strPool = sb乾坤股票池().ToString();

        strGgph = sb个股排行().ToString();

        strHotBk = sb板块排行().ToString();

        strQsRs = sb强势弱势板块().ToString();

        strCWB = sb仓位表().ToString();

        strRdbk = str热点板块();

    }

    protected StringBuilder sb乾坤股票池()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string str = Pub.LoadData(jsonUrl + "hangqing/Hero_Pool.ashx").Replace("\\\"", "\"").Replace("\"[", "[").Replace("]\"", "]");
            var obj = JsonConvert.DeserializeObject<StockPoolEnty>(str);
            if (obj != null)
            {
                sb.Append("<div class=\"hqzx_ly2_r_btn\" id=\"tbPool\">");
                sb.Append("<img p1=\"1\" class=\"shou\" src=\"images/btn_bluestock.jpg\" alt=\"蓝1号股票池\" />");
                sb.Append("<img p1=\"2\" class=\"shou\" src=\"images/btn_redstock.jpg\" alt=\"红1号股票池\" />");
                sb.Append("</div>");

                List<SPItEnty> list = obj.blue;
                sb.AppendLine("<div class=\"hqzx_ly3_r1\" id=\"tbPool_1\">");
                sb.AppendLine("  <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
                sb.AppendLine("    <tr class=\"tableSmallHead\">");
                sb.AppendLine("      <td class=\"gray\">序号</td>");
                sb.AppendLine("      <td class=\"gray\">股票名称</td>");
                sb.AppendLine("      <td class=\"gray\">最大收益</td>");
                sb.AppendLine("      <td class=\"gray\">入榜日期</td>");
                sb.AppendLine("      <td class=\"gray\">入榜价格</td>");
                sb.AppendLine("    </tr>");
                int len = 5;
                if (list.Count < 5)
                    len = list.Count;
                for (int i = 0; i < len; i++)
                {
                    string _class = " ";
                    if (i % 2 == 0)
                        _class = " class=\"bgGray\"";
                    sb.AppendFormat("    <tr {0}>", _class);
                    sb.AppendFormat("      <td>{0}</td>", i + 1);
                    sb.AppendFormat("      <td><a href=\"Gg{1}.shtml\" class=\"b\">{0}</a></td>", list[i].N, list[i].C);
                    sb.AppendFormat("      <td>{0}</td>", OTO.PerRedGre(list[i].F*100, 1, 2, "-", "%"));
                    sb.AppendFormat("      <td>{0}</td>", OTO.ToDate(list[i].DATE, "-"));
                    sb.AppendFormat("      <td>{0}</td>", list[i].P);
                    sb.AppendLine("    </tr>");
                }
                sb.AppendLine("  </table>");
                sb.AppendLine("</div>");

                list = obj.red;
                sb.AppendLine("<div class=\"hqzx_ly3_r1 hide\" id=\"tbPool_2\">");
                sb.AppendLine("  <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
                sb.AppendLine("    <tr class=\"tableSmallHead\">");
                sb.AppendLine("      <td class=\"gray\">序号</td>");
                sb.AppendLine("      <td class=\"gray\">股票名称</td>");
                sb.AppendLine("      <td class=\"gray\">最大收益</td>");
                sb.AppendLine("      <td class=\"gray\">入榜日期</td>");
                sb.AppendLine("      <td class=\"gray\">入榜价格</td>");
                sb.AppendLine("    </tr>");
                len = 5;
                if (list.Count < 5)
                    len = list.Count;
                for (int i = 0; i < len; i++)
                {
                    string _class = " ";
                    if (i % 2 == 0)
                        _class = " class=\"bgGray\"";
                    sb.AppendFormat("    <tr {0}>", _class);
                    sb.AppendFormat("      <td>{0}</td>", i + 1);
                    sb.AppendFormat("      <td><a href=\"Gg{1}.shtml\" class=\"b\">{0}</a></td>", list[i].N, list[i].C);
                    sb.AppendFormat("      <td>{0}</td>", OTO.PerRedGre(list[i].F*100, 1, 2, "-", "%"));
                    sb.AppendFormat("      <td>{0}</td>", OTO.ToDate(list[i].DATE, "-"));
                    sb.AppendFormat("      <td>{0}</td>", list[i].P);
                    sb.AppendLine("    </tr>");
                }
                sb.AppendLine("  </table>");
                sb.AppendLine("</div>");
            }
        }
        catch
        { }
        return sb;
    }

    protected StringBuilder sb个股排行()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string str = Pub.LoadData(jsonUrl + "hangqing/ggph.ashx");
            GgphEnty obj = JsonConvert.DeserializeObject<GgphEnty>(str);
            if (obj != null)
            {
                List<GgphItemEnty> list = obj.沪A;
                sb.AppendLine("  <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
                sb.AppendLine("    <tr class=\"tableSmallHead gray\">");
                sb.AppendLine("      <td>股票代码</td>");
                sb.AppendLine("      <td>股票名称</td>");
                sb.AppendLine("      <td>最新价</td>");
                sb.AppendLine("      <td>涨跌幅</td>");
                sb.AppendLine("      <td>换手率</td>");
                sb.AppendLine("      <td>成交额(万元)</td>");
                sb.AppendLine("      <td>买卖信号</td>");
                sb.AppendLine("      <td>千股千评</td>");
                sb.AppendLine("      <td>体检评分</td>");
                sb.AppendLine("    </tr>");
                int len = 7;
                if (list.Count < 7)
                    len = list.Count;
                for (int i = 0; i < len; i++)
                {
                    string _class = "";
                    if (i % 2 == 0)
                        _class = "class=\"bgGray\"";
                    sb.AppendFormat("    <tr {0}>", _class);
                    sb.AppendFormat("      <td>{0}</td>", list[i].StockId);
                    sb.AppendFormat("      <td><a href=\"Gg{1}.shtml\" class=\"b\">{0}</a></td>", list[i].StockName, list[i].StockId);
                    sb.AppendFormat("      <td><span zxj=\"zxj\" code=\"{0}\" class=\"red\">-</span></td>", list[i].StockId);
                    sb.AppendLine("      <td><span zdf=\"zdf\">-</span></td>");
                    sb.AppendLine("      <td><span hsl=\"hsl\">-</span></td>");
                    sb.AppendLine("      <td><span cje=\"cje\">-</span></td>");
                    sb.AppendLine("      <td><span bs=\"bs\">-</span></td>");
                    sb.AppendFormat("      <td>{0}</td>", list[i].Qgqp);
                    sb.AppendFormat("      <td>{0}</td>", OTO.CoUt(list[i].Tjpf, 1, "-", 0));
                    sb.AppendLine("    </tr>");
                }
                sb.AppendLine("  </table>");
            }
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb热点板块()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string str = Pub.LoadData(jsonUrl + "hangqing/ggph.ashx");
            GgphEnty obj = JsonConvert.DeserializeObject<GgphEnty>(str);
            if (obj != null)
            {
                sb.AppendLine("<div class=\"sjgp\" id=\"hotbk\">");
                sb.AppendLine("  <ul>");
                sb.AppendLine("    <li class=\"sjgp_1\" style=\"text-align:left;\"><img src=\"images/report_ico3.jpg\" /></li>");
                sb.AppendLine("    <li class=\"sjgp_2\"><a href=\"#\" class=\"b\">酒饮料</a></li>");
                sb.AppendLine("    <li class=\"sjgp_2a red\">12.45</li>");
                sb.AppendLine("    <li class=\"sjgp_2a red\">4.36%</li>");
                sb.AppendLine("    <li class=\"sjgp_1 bg_tipR1\">1</li>");
                sb.AppendLine("  </ul>");
                sb.AppendLine("  <div class=\"sjgp_m report_bg\"> 关注理由：近期加息对房地产的影响进一步加大，加上前期政策调控影响... </div>");
                sb.AppendLine("</div>");
            }
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb板块排行()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string str = Pub.LoadData(jsonUrl + "hangqing/bkph.ashx");
            BkphEnty obj = JsonConvert.DeserializeObject<BkphEnty>(str);
            if (obj != null)
            {
                sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
                sb.AppendLine("  <tr class=\"tableSmallHead gray\">");
                sb.AppendLine("    <td >板块名称</td>");
                sb.AppendLine("    <td >涨跌幅</td>");
                sb.AppendLine("    <td >5日涨跌</td>");
                sb.AppendLine("    <td >主力净买</td>");
                sb.AppendLine("    <td >5日净买</td>");
                sb.AppendLine("    <td  width=\"58\">操盘线</td>");
                sb.AppendLine("    <td >股票数量</td>");
                sb.AppendLine("    <td >上涨</td>");
                sb.AppendLine("    <td >下跌</td>");
                sb.AppendLine("    <td >领涨股</td>");
                sb.AppendLine("    <td >弱势股</td>");
                sb.AppendLine("  </tr>");

                List<BkphItEnty> list = obj.行业板块;
                int len = 7;
                if (list.Count < 7)
                    len = list.Count;
                for (int i = 0; i < len; i++)
                {
                    string _class = "class=\"bgGray\"";
                    if (i % 2 == 0)
                        _class = "";
                    sb.AppendFormat("  <tr {0}>", _class);
                    sb.AppendFormat("    <td ><a href=\"Bk{1}.shtml\" class=\"b\">{0}</a></td>", list[i].BKName, list[i].BKCode);
                    sb.AppendFormat("    <td bkzdf=\"bk1\" bkcode1=\"{0}\">-</td>", list[i].BKCode);
                    sb.AppendLine("    <td bkzdf5=\"bk1\">-</td>");
                    sb.AppendLine("    <td bkzl=\"bk1\">-</td>");
                    sb.AppendLine("    <td bkzl5=\"bk1\">-</td>");
                    sb.AppendLine("    <td bknc=\"bk1\">-</td>");
                    sb.AppendFormat("    <td>{0}</td>", list[i].StockCount);
                    sb.AppendFormat("    <td>{0}</td>", list[i].UpCount);
                    sb.AppendFormat("    <td>{0}</td>", list[i].DownCount);
                    sb.AppendFormat("    <td><a href=\"Gg{1}.shtml\" class=\"b\">{0}</a></td>", list[i].LZName, list[i].LZCode);
                    sb.AppendFormat("    <td><a href=\"Gg{1}.shtml\" class=\"b\">{0}</a></td>", list[i].LDName, list[i].LDCode);
                    sb.AppendLine("  </tr>");
                }
                sb.AppendLine("</table>");
            }
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb强买增仓榜()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string str = Pub.LoadData(jsonUrl + "hangqing/gpqr.ashx");
            ZcQmEnty obj = JsonConvert.DeserializeObject<ZcQmEnty>(str);
            if (obj != null)
            {
                sb.AppendLine("<ul class=\"floatLeft marginTop5\">");
                sb.AppendLine("  <li>强买榜：");
                foreach (var m in obj.qbm)
                {
                    sb.AppendFormat("  <a href=\"?code={0}\" class=\"b\">{1}</a> ", m.stockid, m.name);
                }
                sb.AppendLine("  </li>");
                sb.AppendLine("  <li>增仓榜：");
                foreach (var m in obj.zcb)
                {
                    sb.AppendFormat("  <a href=\"?code={0}\" class=\"b\">{1}</a> ", m.stockid, m.name);
                }
                sb.AppendLine("  </li>");
                sb.AppendLine("  <div class=\"clear\"></div>");
                sb.AppendLine("</ul>");
            }
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb强势弱势板块()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string str = Pub.LoadData(jsonUrl + "hangqing/bkqr.ashx");
            QsRsEnty obj = JsonConvert.DeserializeObject<QsRsEnty>(str);
            if (obj != null)
            {
                sb.AppendLine("<ul class=\"floatLeft marginTop10\">");
                sb.AppendLine("  <li>强势板块：");
                foreach (var m in obj.qsbk)
                {
                    sb.AppendFormat("  <a href=\"?code={0}\" class=\"b\">{1}</a> ", m.stockid, m.name);
                }
                sb.AppendLine("  </li>");
                sb.AppendLine("  <li>弱势板块：");
                foreach (var m in obj.rsbk)
                {
                    sb.AppendFormat("  <a href=\"?code={0}\" class=\"b\">{1}</a> ", m.stockid, m.name);
                }
                sb.AppendLine("  </li>");
                sb.AppendLine("  <div class=\"clear\"></div>");
                sb.AppendLine("</ul>");
            }
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb仓位表()
    {
        StringBuilder sb = new StringBuilder();
        //try
        //{
        string str = Pub.LoadData(jsonUrl + "comm/weather.ashx");
        WeatherEnty obj = new WeatherEnty();
        if (!String.IsNullOrEmpty(str))
            obj = JsonConvert.DeserializeObject<WeatherEnty>(str);

        sb.AppendFormat("<div class=\"hqzx_ly1_r1\"> <img src=\"images/weather/w{0}.gif\" alt=\"天气预报-冬日暖阳\" align=\"left\"/ class=\"img\"><br />", obj.weather);
        sb.AppendFormat("{0}", obj.content);
        sb.AppendLine("<div class=\"clearok\"></div>");

        QsRsEnty obj2 = JsonConvert.DeserializeObject<QsRsEnty>(Pub.LoadData(jsonUrl + "hangqing/bkqr.ashx"));
        if (obj != null)
        {
            sb.AppendLine("<ul class=\"floatLeft marginTop10\">");
            sb.AppendLine("  <li>强势板块：");
            foreach (var m in obj2.qsbk)
            {
                sb.AppendFormat("  <a href=\"bk{0}.shtml\" class=\"b\">{1}</a> ", m.stockid, m.name);
            }
            sb.AppendLine("  </li>");
            sb.AppendLine("  <li>弱势板块：");
            foreach (var m in obj2.rsbk)
            {
                sb.AppendFormat("  <a href=\"bk{0}.shtml\" class=\"b\">{1}</a> ", m.stockid, m.name);
            }
            sb.AppendLine("  </li>");
            sb.AppendLine("  <div class=\"clear\"></div>");
            sb.AppendLine("</ul>");
        }

        sb.AppendLine("<div class=\"clearok\"></div>");
        sb.AppendLine("<div class=\"weather_scjd_title marginTop10 font-weight\">后市指南</div>");
        sb.AppendLine("<div class=\"clearok\"></div>");
        sb.AppendLine("<div class=\"weather_scjd_content\">");

        sb.AppendLine("<div class=\"weather_scjd_content1\"><img src=\"images/ico_advice.jpg\" vspace=\"10\" alt=\"建议仓位\" /><br />");
        sb.AppendFormat("  <span class=\"red font35 font_arial\">{0}%</span></div>", obj.posi);
        sb.AppendLine("<div class=\"weather_scjd_content2\">");
        sb.AppendLine("  <ul>");
        sb.AppendFormat("    <li><span class=\"gray\">短期策略：</span>{0}</li>", obj.short_strategy);
        sb.AppendFormat("    <li><span class=\"gray\">中期策略：</span>{0}</li>", obj.long_strategy);
        sb.AppendLine("  </ul>");
        sb.AppendLine("</div>");

        sb.AppendLine("<div class=\"clearok\"></div>");

        ZcQmEnty obj3 = JsonConvert.DeserializeObject<ZcQmEnty>(Pub.LoadData(jsonUrl + "hangqing/gpqr.ashx"));
        if (obj3 != null)
        {
            sb.AppendLine("<ul class=\"floatLeft marginTop5\">");
            sb.AppendLine("  <li>强买榜：");
            foreach (var m in obj3.qbm)
            {
                sb.AppendFormat("  <a href=\"gg{0}.shtml\" class=\"b\">{1}</a> ", m.stockid, m.name);
            }
            sb.AppendLine("  </li>");
            sb.AppendLine("  <li>增仓榜：");
            foreach (var m in obj3.zcb)
            {
                sb.AppendFormat("  <a href=\"gg{0}.shtml\" class=\"b\">{1}</a> ", m.stockid, m.name);
            }
            sb.AppendLine("  </li>");
            sb.AppendLine("  <div class=\"clear\"></div>");
            sb.AppendLine("</ul>");
        }

        sb.AppendLine("</div>");
        sb.AppendLine("</div>");


        //}
        //catch { }
        return sb;
    }

    /// <summary>
    /// 头条
    /// </summary>
    /// <returns></returns>
    protected StringBuilder sbScjd()
    {
        StringBuilder sb = new StringBuilder();
        //try
        //{

            string str = Pub.LoadData(jsonUrl + "news/NewsListMany.ashx?typeid=0112&top=5");
            List<NewsList> obj = JsonConvert.DeserializeObject<List<NewsList>>(str);
            if (obj.Count > 0)
            {
                int i = 0;
                foreach (var m in obj[0].list)
                {
                    if (i == 0)
                    {
                        NewsContentEnty obj2 = JsonConvert.DeserializeObject<NewsContentEnty>(Pub.LoadData(jsonUrl + "/news/UNews.ashx?id=" + m.Id));
                        if (obj2 != null)
                        {
                            sb.AppendFormat("<li class=\"h2 b\"><a href=\"{1}\">{0}</a></li>", obj2.Title, GetNewsUrl("01", "0112", m.Id));
                            sb.AppendFormat("<li class=\"font12 gray\">{0}<a href=\"{1}\" class=\"r\">[详细]</a></li>", OTO.CutStr(obj2.Summary, 40), GetNewsUrl("01", "0112", m.Id));
                            sb.Append("<li class=\"line\" style=\"height:10px\"></li>");
                        }
                    }
                    else
                    {
                        sb.AppendFormat("<li> ·<a href=\"{1}\" class=\"b\">{0}</a></li>", m.Title, GetNewsUrl("00", "0112", m.Id));
                    }
                    i++;
                }
            }

        //}
        //catch { }
        return sb;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    protected StringBuilder sbScjd2()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "news/NewsListMany.ashx?typeid=0303&top=2";
            string str = Pub.LoadData(url);
            List<NewsList> obj = JsonConvert.DeserializeObject<List<NewsList>>(str);
            if (obj.Count > 0)
            {
                foreach (var m in obj[0].list)
                {
                    sb.AppendFormat("<li> ·<a href=\"{1}\" class=\"b\">{0}</a></li>", m.Title, GetNewsUrl("00", "0303", m.Id), wwwUrl);
                }
            }
            sb.Append("<li class=\"line\" style=\"height:15px\"></li>");


        }
        catch { }
        return sb;
    }

    /// <summary>
    /// 头条下，大盘，板块，个股信息
    /// </summary>
    /// <returns></returns>
    protected StringBuilder sbScjd3()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "news/NewsListMany.ashx?typeid=0303,0304,0305&top=1";
            string str = Pub.LoadData(url);
            List<NewsList> obj = JsonConvert.DeserializeObject<List<NewsList>>(str); sb.Append("<div class=\"hqzx_ly1_c2\"><ul>");
            foreach (var item in obj)
            {
                switch (item.typeid)
                {
                    case "0303":
                        for (int i = 0; i < item.list.Length; i++)
                        {
                            if (i == 0)
                                sb.AppendFormat("<li>·<span class=\"font14 font-weight\"><a href=\"{0}\">{1}</a></span> | <a href=\"{3}\" target=\"_blank\">{2}</a></li>",GetNewListUrl("10", item.typeid,1), item.typename, item.list[0].Title, GetNewsUrl("10", item.typeid, item.list[0].Id));
                            else
                                sb.AppendFormat("<li>·<a href=\"{1}\" target=\"_blank\">{0}</a></li>", item.list[i].Title, GetNewsUrl("10", item.typeid, item.list[i].Id));
                        }
                        break;
                    case "0304":
                        for (int i = 0; i < item.list.Length; i++)
                        {
                            if (i == 0)
                                sb.AppendFormat("<li>·<span class=\"font14 font-weight\"><a href=\"{0}\">{1}</a></span> | <a href=\"{3}\" target=\"_blank\">{2}</a></li>", GetNewListUrl("10", item.typeid, 1), item.typename, item.list[0].Title, GetNewsUrl("10", item.typeid, item.list[0].Id));
                            else
                                sb.AppendFormat("<li>·<a href=\"{1}\" target=\"_blank\">{0}</a></li>", item.list[i].Title, GetNewsUrl("10", item.typeid, item.list[i].Id));
                        }
                        break;
                    case "0305":
                        for (int i = 0; i < item.list.Length; i++)
                        {
                            if (i == 0)
                                sb.AppendFormat("<li>·<span class=\"font14 font-weight\"><a href=\"{0}\">{1}</a></span> | <a href=\"{3}\" target=\"_blank\">{2}</a></li>", GetNewListUrl("10", item.typeid, 1), item.typename, item.list[0].Title, GetNewsUrl("10", item.typeid, item.list[0].Id));
                            else
                                sb.AppendFormat("<li>·<a href=\"{1}\" target=\"_blank\">{0}</a></li>", item.list[i].Title, GetNewsUrl("10", item.typeid, item.list[i].Id));
                        }
                        break;
                }
            }
            sb.Append("</ul></div>");
        }
        catch { }
        return sb;
    }


    protected string str热点板块()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string str = Pub.LoadData(jsonUrl + "comm/HotCalendar.ashx");
            List<HotBkEnty> list = JsonConvert.DeserializeObject<List<HotBkEnty>>(str);
            int len = 4;
            if (list.Count < len)
                len = list.Count;
            for (int i = 0; i < len; i++)
            {
                sb.AppendLine("<ul>");
                sb.AppendLine("<li class=\"sjgp_1\" style=\"text-align:left;\"><img src=\"images/report_ico2.jpg\" /></li>");
                sb.AppendFormat("<li class=\"sjgp_2 bottom_line\"><a href=\"bk{0}.shtml\" class=\"b\">{1}</a></li>", list[i].bkid, list[i].bkname);
                sb.AppendFormat("<li class=\"sjgp_2a bottom_line\">{0}</li>", OTO.PerRedGre(list[i].F,2,"-","%"));
                sb.AppendFormat("<li class=\"sjgp_2a bottom_line\">{0}</li>", OTO.PerRedGre(list[i].F5, 2, "-", "%"));
                sb.AppendFormat("<li class=\"sjgp_1 bottom_line \"><div class=\"{0}\" style=\"width:30px;\" title=\"{2}\">{1}</div></li>", list[i].BC >= 0 ? "bg_tipR1" : "bg_tipG1", list[i].BC, Pub.NcTip(list[i].BC));
                sb.AppendLine("</ul>");
                sb.AppendFormat("<div class=\"sjgp_m report_bg hide\">{0}</div>", list[i].reason);
            }
        }
        catch { }
        return sb.ToString();
    }
}